import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'Login',
      component: () => import('../views/Account/Login.vue'),
    },
    {
      path: '/Menu',
      name: 'Menu',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Menu.vue'),
      children: [
        {
          path: '/PermissionGet',
          name: 'PermissionGet',
          // route level code-splitting
          // this generates a separate chunk (About.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import('../views/Permission/PermissionGet.vue'),
        },
        {
          path: '/RoleGet',
          name: 'RoleGet',
          // route level code-splitting
          // this generates a separate chunk (About.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import('../views/Role/RoleGet.vue'),
        },
        {
          path: '/AccountGet',
          name: 'AccountGet',
          // route level code-splitting
          // this generates a separate chunk (About.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import('../views/Account/AccountGet.vue'),
        },
        {
          path: '/home',
          name: 'home',
          component: HomeView,
        },
        {
          path: '/about',
          name: 'about',
          // route level code-splitting
          // this generates a separate chunk (About.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import('../views/AboutView.vue'),
        },
        {
          path: '/user-profile',
          name: 'UserProfile',
          component: () => import('../views/Account/UserProfile.vue'),
        },
        {
          path: '/Traceability',
          name: 'Traceability',
          component: () => import('../views/TraceabilityView.vue')
        },
      ]
    },
    {
      path: '/TraceabilityDetail',
      name: 'TraceabilityDetail',
      component: () => import('../views/TraceabilityDetail.vue')
    },
  ],
})

// // 全局前置导航守卫
// router.beforeEach((to, from, next) => {
//   // 登录页路径（根据你的实际路径调整）
//   const loginPath = '/';
//   // 假设token存储在localStorage
//   const token = localStorage.getItem('token');
//   if (to.path !== loginPath && !token) {
//     // 未登录，强制跳转到登录页
//     next(loginPath);
//   } else {
//     // 已登录或访问登录页，放行
//     next();
//   }
// });

export default router
